﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CustomControls;
using Outlook = Microsoft.Office.Interop.Outlook;
using Bds.Inject;
using System.Text.RegularExpressions;
using DienLib.ReportLib;

namespace DienVu
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class HalReportWPF : CustomWindow
    {
        #region Global Variable
        //MouseHook g_mouseHook = new MouseHook();
        MouseKeyboardLibrary.KeyboardHook g_keyboardHook;
        DienLib.ReportLib.Configuration g_config;
        const double heightFormOrigin = 360; // Unchanged
        const double heightExpander = 323; // Changed if add more Expander (Click on bottom border & drag just a little bit to see the height of expander change
        const double heightForm = heightExpander + heightFormOrigin - 26;
        #endregion

        #region Constructor & Init
        public HalReportWPF()
        {
            if (InitializeFirst() == false) { CloseOnInit(); return; } // Check If config file is there, if yes then Parse Config File.
            InitializeComponent();  // Init all Buttons, Controls, ...
            this.Height = heightFormOrigin;
            InitializeExtra(); // Add Event & Context Menu for Button
        }

        /// <summary>
        /// Call this after InitiliazeComponent to avoid null Button
        /// </summary>
        private void InitializeExtra()
        {
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butDailyReport, "Daily Report", g_config, Configuration.Paths.FILE_DailyReport);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butEXP, "Explosive Inventory", g_config, Configuration.Paths.FILE_Explosive);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butCable, "Cable Record", g_config, Configuration.Paths.FILE_CableRecord);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butCCL, "CCL Tracking", g_config, Configuration.Paths.FILE_CCLTracking);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butPerfRisk, "Perforation Risk", g_config, Configuration.Paths.FILE_PerfRisk);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butJobPlan, "Job Planning", g_config, Configuration.Paths.FILE_PerfPlan);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butMaintenance, "CasedHole Maintenance", g_config, Configuration.Paths.FILE_CHMaintenance);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butPCE, "PCE", g_config, Configuration.Paths.FILE_PCE);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butHazardHunt, "Hazard Hunt", g_config, Configuration.Paths.FILE_HazardHunt);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butHOC, "HOC/SOC", g_config, Configuration.Paths.FILE_HOC);
            ButtonEvent.AddEvent_ClickDragDrop_BasicButton(butChopper, "Chopper Booking", g_config, Configuration.Paths.FILE_Chopper);

            InitButtonContextMenu();

        }

        private void InitButtonContextMenu()
        {
            ContextMenu.BaseMenu menu;
            ContextMenu.BaseStyle style = new DienVu.ContextMenu.BaseStyle(DienVu.ContextMenu.StyleColor.Normal); //Style style = FindResource("DienStyle") as Style;
            
            // button Explosive Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Report", DienVu.ContextMenu.Icons.MailOutBlue, MenuItem_DailyReport_Send_Click, true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_DailyReport], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, MenuItem_DailyReport_OutlookSetting_Click, false);
            this.butDailyReport.ContextMenu = menu;
            // button Explosive Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Inventory", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_Explosive], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_Explosive], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butEXP.ContextMenu = menu;
            // button CCL Tracking Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Tracking", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_CCLTracking], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_CCLTracking], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butCCL.ContextMenu = menu;
            // button Job Planning Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send JobPlan", DienVu.ContextMenu.Icons.MailOutRed, g_config[Configuration.Paths.FILE_PerfPlan], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchRed, g_config[Configuration.Paths.FOLDER_PerfPlan], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserRed, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butJobPlan.ContextMenu = menu;
            // button Perforation Risk Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send PerfRisk", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_PerfRisk], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_PerfPlan], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butPerfRisk.ContextMenu = menu;
            // button Cable Record Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Record", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_CableRecord], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_CableRecord], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butCable.ContextMenu = menu;
            // button CH Maintenance Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Checklist", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_CHMaintenance], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_CHMaintenance], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butMaintenance.ContextMenu = menu;
            // button PCE Inventory Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Inventory", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_PCE], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_PCE], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butPCE.ContextMenu = menu;
            // button Hazard Hunt Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Report", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_HazardHunt], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_HazardHunt], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butHazardHunt.ContextMenu = menu;
            // button HOC Report Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Report", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_HOC], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_HOC], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butHOC.ContextMenu = menu;
            // button Chopper Booking Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("Send Booking", DienVu.ContextMenu.Icons.MailOutBlue, g_config[Configuration.Paths.FILE_Chopper], true);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchBlue, g_config[Configuration.Paths.FOLDER_Chopper], false);
            menu.AddItem("Mail Preset", DienVu.ContextMenu.Icons.UserBlue, (s, e) => System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_Poster]), false);
            this.butChopper.ContextMenu = menu;
            // button FARPAC Context Menu
            menu = new ContextMenu.BaseMenu(style);
            menu.AddItem("New Farpac", DienVu.ContextMenu.Icons.Add, (s, e) => NewFarpac.ShowDialog(g_config), false);
            menu.AddItem("Open Folder", DienVu.ContextMenu.Icons.SearchGreen, g_config[Configuration.Paths.FOLDER_FARPAC], false);
            //menu.AddItem("Recent Farpac", DienVu.ContextMenu.Icons.SearchRed, ItemClickHandler: null, Highlight: true);
            menu.AddItem(new ContextMenu.FolderItem(new System.IO.DirectoryInfo(g_config[Configuration.Paths.FOLDER_FARPAC]), "Recent Farpac", DienVu.ContextMenu.Icons.ClockGreen, false));
            this.butFARPAC.ContextMenu = menu;
        }


        /// <summary>
        /// Better place this method before InitializeComponent() to help CloseOnInit() activate before any "Loaded +=" in InitializeComponent
        /// </summary>
        /// <returns>Return True mean Init Success. If False you need to cancel Form Load</returns>
        private bool InitializeFirst()
        {
            if (System.Threading.Thread.CurrentThread.CurrentCulture.LCID != new System.Globalization.CultureInfo("en-US").LCID)
            {
                DienLib.PopUp.PopUpOK.ShowDialog("\"Your current REGIONAL is different than EN-US !\"\r\n\r\n" +
                                                 "Will support Multi-language Region soon !\r\n\r\n" +
                                                 "If you got problem during use :\r\n" +
                                                 "         \"Change your Regional Format to English\"\r\n\r\n" +
                                                 "   |  Control Panel >> Regional and Language Options  |\r\n" +
                                                 "   |  >> Regional Options Tab  >> Standard & Format  |\r\n" +
                                                 "   |  >> English (United State) >> Click “OK” !             |\r\n" +
                                                 "          (Note: Location no need to change)",
                                                 "HalReport-PTTEP");
            }

            try
            {
                string AppFolder = System.AppDomain.CurrentDomain.BaseDirectory;
                string ConfigFilePath = System.IO.Path.Combine(AppFolder, "config.xlsx");
                if (!System.IO.File.Exists(ConfigFilePath))
                {
                    System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
                    // Get current application path
                    //dialog.InitialDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // .DLL Assembly
                    //dialog.InitialDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); // .EXE Assembly
                    //dialog.InitialDirectory = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); // Another
                    dialog.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
                    dialog.FileName = "config.xlsx";
                    dialog.Title = "LOOK FOR \"config\" FILE";
                    dialog.Filter = "Software Configuration File|config.xlsx";
                    System.Windows.Forms.DialogResult res = dialog.ShowDialog();
                    if (res != System.Windows.Forms.DialogResult.OK)
                    {   // Cancel Then Extract Default Config from .EXE
                        DienLib.PopUp.PopUpResult res2 = DienLib.PopUp.PopUpOKCancel.ShowDialog("Will use Default Config File !", "NO CONFIG FILE FOUND");
                        if (res2 != DienLib.PopUp.PopUpResult.OK) { return false; }
                        // Else Extract Default Config
                        try { System.IO.File.WriteAllBytes(ConfigFilePath, DienVu.Properties.Resources.config); }
                        catch (Exception ex)
                        {   // Extract FAIL => Close App & Exit
                            DienLib.PopUp.PopUpOK.ShowDialog("Cannot create Default Config File ! Application will now EXIT ...", "DEFAULT CONFIG FILE ERROR");
                            return false;
                        };
                    }
                    // User OK with the File
                    if (System.IO.File.Exists(dialog.FileName)) ConfigFilePath = dialog.FileName;
                    else
                    {
                        DienLib.PopUp.PopUpOK.ShowDialog("Sorry ! No Config File Found ! Application will now EXIT ...", "NO CONFIG FILE FOUND !");
                        return false;
                    }
                }

                // OK ! Get the config file already ...
                g_config = new DienLib.ReportLib.Configuration(ConfigFilePath, true);
            }
            catch (Exception ex) { DienLib.PopUp.PopUpOK.ShowDialog("Initialized Fail : " + ex.Message, "HalReport WILL NOW CLOSE"); return false; }

            // Init success => Return TRUE
            return true;
        }

        /// <summary>
        /// Have to call return after call this method to avoid add duplicate close again & again.
        /// </summary>
        private void CloseOnInit()
        {
            this.Loaded += (o, e) => { this.Close(); e.Handled = true; }; // Handled = true will not call any other Loaded anymore.
            return;
        }

        public void ServicePopUp()
        {   //@"..\..\Resources\SQ_Poster.pdf"
            string PosterFilePath = g_config[Configuration.Paths.FILE_Poster];
            try { System.IO.File.WriteAllBytes(PosterFilePath, DienVu.Properties.Resources.SQ_Poster); }
            catch (Exception e) { }; // File is in use then bypass => Reopen again !

            System.Diagnostics.Process.Start(PosterFilePath); // Cannot Get Process from Start(..) because if PDF already open, it will not return process correctly (No MainWindowHandle | MainWindowTitle)

            int i = 40; bool stopWait = false; List<IntPtr> adobes = new List<IntPtr>();
            while (!stopWait)
            {   // Implement for Adobe Reader only. Need further more for Foxit, ... etc ... Better implement FindWindowLike search all Proc & Thread. No need put Proc parameter.
                System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName("AcroRd32");
                foreach (System.Diagnostics.Process proc in procs)
                {
                    string s = PosterFilePath.Substring(PosterFilePath.LastIndexOf('\\') + 1, PosterFilePath.LastIndexOf('.') - PosterFilePath.LastIndexOf('\\'));
                    adobes.AddRange(DienLib.WinAPI.FindWindowLike(proc, s.Trim().ToLower(), DienLib.FindCulture.PARTIAL_MATCH_IGNORE_CASE));
                }
                stopWait = (adobes.Count != 0) | (i == 0);
                if (stopWait) break; else { System.Threading.Thread.Sleep(250); i--; } // Timeout : 10 Sec = 250 x i = 40
            }

            if (i == 0 | adobes.Count == 0)
            {
                DienLib.PopUp.PopUpOK.ShowDialog("Cannot open PDF File SQ_Poster.pdf ! Something wrong with your PDF Reader ? Try again later", "TOO LONG OPEN PDF FILE");
                return;
            }

            // adobes.Count != 0
            DienLib.WinAPI.SetForegroundWindow(adobes[0]);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.ControlKey, false);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.L, false);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.L, true);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.ControlKey, true);
        }
       
        private void CustomWindow_Loaded(object sender, RoutedEventArgs e)
        {
            g_keyboardHook = new MouseKeyboardLibrary.KeyboardHook();
            // Additional for HotKey Activate Form
            //g_mouseHook.MouseMove += new System.Windows.Forms.MouseEventHandler(mouseHook_MouseMove);
            //g_mouseHook.MouseDown += new System.Windows.Forms.MouseEventHandler(mouseHook_MouseDown);
            //g_mouseHook.MouseUp += new System.Windows.Forms.MouseEventHandler(mouseHook_MouseUp);
            //g_mouseHook.MouseWheel += new System.Windows.Forms.MouseEventHandler(mouseHook_MouseWheel);
            //g_mouseHook.DoubleClick += new System.EventHandler(mouseHook_DoubleClick);

            g_keyboardHook.KeyDown += new System.Windows.Forms.KeyEventHandler(keyboardHook_KeyDown);
            //keyboardHook.KeyUp += new System.Windows.Forms.KeyEventHandler(keyboardHook_KeyUp);
            //keyboardHook.KeyPress += new System.Windows.Forms.KeyPressEventHandler(keyboardHook_KeyPress);

            //mouseHook.Start();
            g_keyboardHook.Start();

            //comboBox1.ItemsSource = config.JobTypes;
            //comboBox1.DisplayMemberPath = "ShortName";

            // Xong xuoi het moi bat dau mo Poster
            ServicePopUp(); // Phai de ServicePopUp ra sau thoi vi con bung file Poster phai biet duog dan ma. De ServicePopUp truoc g_config hay hon vi trong thoi gian nguoi su dung nhin g_config thi se thay Poster. Tranh thu duoc thoi gian Load !
        }

        private void expander1_Expanded(object sender, RoutedEventArgs e)
        {
            this.Height = heightForm;
        }

        private void expander1_Collapsed(object sender, RoutedEventArgs e)
        {
            this.Height = heightFormOrigin;
        }

        /// <summary>
        /// Disable ALT-F4 function on this form
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e)
        {
            // No need to use e argument. But if system slow, the eventhandler activate when you already release finger from keyboard then this will working wrong.
            if ((Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)) && Keyboard.IsKeyDown(Key.F4))
                // Better implement e argument but have to use AltMemory to remember ALT down
                e.Handled = true;
            else // If not ALT-F4 then back to normal
                base.OnPreviewKeyDown(e);
        }
        #endregion

        #region SpecialButtonCLICK
        private void butSummit_Click(object sender, RoutedEventArgs e)
        {
            DienLib.PopUp.PopUpResult butMsg = DienLib.PopUp.PopUpOKCancel.ShowDialog("Highly recommend you \"close ALL Open Window FIRST\" before Click OK !", "Demo \"Auto fill SUMMIT Job Package\"");
            if (butMsg == DienLib.PopUp.PopUpResult.CANCEL) return;

            IntPtr hWnd = DienLib.SummitLib.Command.StartSummit();
            //MessageBox.Show(System.Reflection.Assembly.GetExecutingAssembly().Location);
            Injector.InvokeRemote(hWnd, "DemoSummitWPF.dll", "DienVu.MainWindow", "ShowForm", new object[] { hWnd, g_config.FullPath });
        }

        private void butNetwork_Click(object sender, RoutedEventArgs e)
        {
            SwitchNetConfig.MainForm netForm = new SwitchNetConfig.MainForm();
            netForm.Show();
        }

        private void txtDienVu_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DienLib.PopUp.PopUpResult msr = DienLib.PopUp.PopUpOKCancel.ShowDialog("This is \"ONE-CLICK FEED-BACK\" if you see error during using HALREPORT :\r\n" +
                "\r\n   1). Move your mouse point the error window on the screen & CLICK to capture !" +
                "\r\n   2). An auto-create e-mail will wrap that Error Window & send to me for fixing !" +
                "\r\n\r\nThank you very much for your \"ONE-CLICK\" feed-back ! - (Dien Vu)", "Screen Capture Your Error !");
            if (msr == DienLib.PopUp.PopUpResult.OK) DienLib.PopUp.PopUpOK.ShowDialog("This feature coming very soon for debug error & receive feed-back from user !", "Feature cooming soon !");

        }

        private void butDatabase_Click(object sender, RoutedEventArgs e)
        {

        }


        #endregion

        #region GlobalHook
        private void mouseHook_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {

        }

        private void keyboardHook_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control & e.Alt & e.KeyCode == System.Windows.Forms.Keys.Q)
            {   // Why cannot use e.KeyCode = Keys.Space here ?
                this.WindowState = System.Windows.WindowState.Minimized;
                this.WindowState = System.Windows.WindowState.Normal;
                this.Dispatcher.BeginInvoke(new test(test1));
            }
            else if (e.Control & e.KeyCode == System.Windows.Forms.Keys.Q)
            {
                //this.IsEnabled = false;
                this.WindowState = System.Windows.WindowState.Minimized;
                this.WindowState = System.Windows.WindowState.Normal;
                //this.IsEnabled = true; // To avoid Space Press an active button on this form
            }
        }

        public void test1()
        {
            DienLib.PopUp.PopUpResult res = DienLib.PopUp.PopUpOKCancel.ShowDialog(@"WARNING : You will now modify the ""CONFIG.XLSX"" for HAL-REPORT. If you don't know what is it ? Then better you ""click CANCEL""", "CONFIGURATION FILE for HAL-REPORT");
            if (res == DienLib.PopUp.PopUpResult.OK) DienLib.OfficeLib.Excel.OpenBookVisible(g_config.FullPath);
        }

        delegate void test();

        private void CustomWindow_Closed(object sender, EventArgs e)
        {
            if (g_keyboardHook != null)
            {
                g_keyboardHook.KeyDown -= keyboardHook_KeyDown;
                g_keyboardHook.Stop(); g_keyboardHook = null;
            }
        }

        #endregion

        #region MenuItemClick
        private void MenuItem_Click_1_1(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\MultiSplit\User Manual 9923-24 MultiSplit v1.0 hires.pdf");
        }

        private void MenuItem_Click_1_2(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\MultiSplit\Hydraulic & Pneumatic Diagram 9845 9923 9924.pdf");
        }

        private void MenuItem_Click_1_3(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\MultiSplit\Electrical Diagram 9923+9924.pdf");
        }

        private void MenuItem_Click_1_4(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\MultiSplit\Set Min & Max (Speed adjustment) for Hydraulic Motor of Cable.pdf");
        }

        private void MenuItem_Click_1_5(object sender, RoutedEventArgs e)
        {

        }

        private void MenuItem_Click_1_6(object sender, RoutedEventArgs e)
        {

        }

        private void MenuItem_Click_1_7(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\MultiSplit\Troubleshooting of Gas detectors currently in use.pdf");
        }

        private void MenuItem_Click_1_8(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-5061_CH - PM and Troubleshooting Guidelines for CH Units - rev B.pdf");
        }

        private void MenuItem_Click_2_1(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\LOGIQ\Configuration and Wiring Diagram of Unit PTT ASEP#8133.doc");
        }

        private void MenuItem_Click_2_2(object sender, RoutedEventArgs e)
        {

        }

        private void MenuItem_Click_3_1(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod");
        }

        private void MenuItem_Click_3_2(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-5061_CH - PM and Troubleshooting Guidelines for CH Units - rev B.pdf");
        }

        private void MenuItem_Click_3_3(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-4612_CH - Perforating Operations in GOT - rev F.pdf");
        }

        private void MenuItem_Click_3_4(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-452_CH - Selective Run - Plug and gun - rev B.pdf");
        }

        private void MenuItem_Click_3_5(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-4611_CH - Perforating in High Temperature Wells - rev D.pdf");
        }

        private void MenuItem_Click_3_6(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-437_CH - RIH & POOH Procedure with monocable - rev F.pdf");
        }

        private void MenuItem_Click_3_7(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-401_CH - Use of Monocables in GOT - rev F.pdf");
        }

        private void MenuItem_Click_4_1(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\JSA");
        }

        private void MenuItem_Click_4_2(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\JSA\JSA-THA-HAL-LP-134 - CH_Rig up & Rig down in offshore platform with Mast.doc");
        }

        private void MenuItem_Click_4_3(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\JSA\JSA-THA-HAL-LP-255 - Marking and breaking a connection.docx");
        }

        private void MenuItem_Click_4_4(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\JSA\JSA-THA-HAL-LP-118 - CH_Perforating in offshore platform.doc");
        }

        private void MenuItem_Click_4_5(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\JSA\Perforating Risk.xls");
        }

        private void MenuItem_Click_5_1(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\WorkMethod\WM-THA-HAL-LP-6006_CH - Reporting Distribution Lists - rev P.pdf");
        }

        private void MenuItem_Click_5_2(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\Checklist\Checklist for Lifting-Shipping equipment - Offshore - rev 1.xlsx");
        }

        private void MenuItem_Click_5_3(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\Checklist\WM-THA-HAL-WP-3001_CH - Unit rig up checklist - rev B.pdf");
        }

        private void MenuItem_Click_5_4(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\Checklist\HWI0744 checked by Dien Vu - 29.Nov.11.xls");
        }

        /// <summary>
        /// Currently Support only Adobe Reader. Further implement FindWindowLike
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click_6(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"..\..\Resource\SQ_Poster.pdf"); // Cannot Get Process from Start(..) because if PDF already open, it will not return process correctly (No MainWindowHandle | MainWindowTitle)
            int i = 10; bool stopWait = false; List<IntPtr> adobes = new List<IntPtr>();
            while (!stopWait)
            {   // Implement for Adobe Reader only. Need further more for Foxit, ... etc ... Better implement FindWindowLike search all Proc & Thread. No need put Proc parameter.
                System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName("AcroRd32");
                foreach (System.Diagnostics.Process proc in procs)
                {
                    adobes.AddRange(DienLib.WinAPI.FindWindowLike(proc, "sq_poster", DienLib.FindCulture.PARTIAL_MATCH_IGNORE_CASE));
                }
                stopWait = (adobes.Count != 0) | (i == 0);
                if (stopWait) break; else { System.Threading.Thread.Sleep(500); i--; } // Timeout : 5 Sec
            }

            if (i == 0 | adobes.Count == 0)
            {
                DienLib.PopUp.PopUpOK.ShowDialog("Cannot open PDF File SQ_Poster.pdf ! Something wrong with your PDF Reader ? Try again later", "TOO LONG OPEN PDF FILE");
                return;
            }

            // adobes.Count != 0
            DienLib.WinAPI.SetForegroundWindow(adobes[0]);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.ControlKey, false);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.L, false);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.L, true);
            DienLib.WinAPI.PressKey(System.Windows.Forms.Keys.ControlKey, true);
        }

        private void MenuItem_DailyReport_OutlookSetting_Click(object sender, RoutedEventArgs e)
        {
            FlowDocument signature;
            DienLib.PopUp.PopUpResult res = DienLib.OfficeLib.PopUpOutlookSetting.ShowDialog(out signature);
            if (res == DienLib.PopUp.PopUpResult.SAVE) Signature = signature;
        }

        FlowDocument Signature;
        private void MenuItem_DailyReport_Send_Click(object sender, RoutedEventArgs e)
        {
            //DienLib.OfficeLib.PopUpTest.ShowDialog();
            string title = "Daily_Report_" + Unit_Prefix + Unit_Num + "_" +
            DateTime.Today.ToString("dMMMyy", System.Globalization.CultureInfo.InvariantCulture) + "_" + Unit_Field;
            string to = To_DailyReport;
            string cc = CC_DailyReport;
            string attach = At_DailyReport;
            //string body = "Team,\r\nPlease find attached \"" + attach.Substring(attach.LastIndexOf('\\') + 1) + "\"";
            FlowDocument body = new FlowDocument();

            DienLib.OfficeLib.Outlook.sendReport(title, to, cc, attach, body, Signature);
        }

        private void MenuItem_DailyReport_OpenFolder_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(g_config[Configuration.Paths.FOLDER_DailyReport]);
        }

        private void MenuItem_FarPac_Recent_Click(object sender, RoutedEventArgs e)
        {

        }

        private void MenuItem_FarPac_OpenFolder_Click(object sender, RoutedEventArgs e)
        {
            if (System.IO.File.Exists(g_config[Configuration.Paths.FOLDER_FARPAC]))
                System.Diagnostics.Process.Start(g_config[Configuration.Paths.FOLDER_FARPAC]);
        }

        private void MenuItem_FarPac_New_Click(object sender, RoutedEventArgs e)
        {

        }

        private void MenuItem_JobPlan_Send_New_Click(object sender, RoutedEventArgs e)
        {

        }

        private void MenuItem_JobPlan_ShipTo_Click(object sender, RoutedEventArgs e)
        {

        }

        private void MenuItem_JobPlan_TicketNo_Click(object sender, RoutedEventArgs e)
        {

        }
        #endregion

        #region MAIL Constant
        const string MySignature = "Dien Vu";

        const string Unit_Prefix = "ELU"; // E-line Unit
        const string Unit_Num = "8434";
        const string Unit_Field = "GBN";

        const string To_DailyReport = "Duangporn.Soponsooksatit@Halliburton.com; FSKLENGLP@Halliburton.com; German.Reynosa@Halliburton.com; Richard.Sankar@Halliburton.com; Rorsalan.Hadkhajae@Halliburton.com; Sunisa.Prom-In@halliburton.com; Thurdsak.Aroontat@Halliburton.com";
        const string CC_DailyReport = "Attagowit.Disara@Halliburton.com";
        const string At_DailyReport = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_WeeklyHH = "Badung.Baroto@halliburton.com; Dithapong Maneedamkullaset; German.Reynosa@Halliburton.com; Richard.Sankar@Halliburton.com";
        const string CC_WeeklyHH = CC_Team;
        const string At_WeeklyHH = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_WeeklySOC = "GBS.Wellserv-supv2@pttep.com; GBS.WellService-Supv@pttep.com; Sunisa.Prom-In@halliburton.com; Richard.Sankar@Halliburton.com; Badung.Baroto@Halliburton.com";
        const string CC_WeeklySOC = CC_Team;
        const string At_WeeklySOC = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_WeeklyPCE = "Richard.Sankar@Halliburton.com; Badung.Baroto@halliburton.com; German.Reynosa@Halliburton.com; Karun.Ammaro@Halliburton.com; Samart.Sirirat@Halliburton.com";
        const string CC_WeeklyPCE = CC_Team;
        const string At_WeeklyPCE = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_WeeklyCable = "Badung.Baroto@halliburton.com; German.Reynosa@Halliburton.com; Grant.Devlin@halliburton.com; Richard.Sankar@Halliburton.com; Sadet.Kongmuang@halliburton.com; Wirat.Chumnum@halliburton.com";
        const string CC_WeeklyCable = CC_Team;
        const string At_WeeklyCable = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_WeeklyCCL = "German.Reynosa@Halliburton.com; Badung.Baroto@halliburton.com; Richard.Sankar@Halliburton.com";
        const string CC_WeeklyCCL = CC_Team;
        const string At_WeeklyCCL = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_WeeklyEXP = "Richard.Sankar@halliburton.com; Badung.Baroto@halliburton.com; Krisda.Limpinyok@halliburton.com; Oran.Sangsuwan@halliburton.com; bongkot.wellservice.hlb1@pttep.com; BQP_Halliburton2@pttep.com; Wellservice-Supt@pttep.com; BONGKOT.Rigless@pttep.com; BONGKOT.Rigless2@pttep.com; Arthit.wellservice.HLB1@pttep.com; Arthit.Wellservice.HLB2@pttep.com; GBS.Wellservice-Halliburton2@pttep.com; GBS.Wellservice-Halliburton1@pttep.com; German.Reynosa@Halliburton.com; GBS.WellService-Supv@pttep.com; GBS.Wellserv-supv1@pttep.com; GBS.Wellserv-supv2@pttep.com; GBS.Safety-Officer@pttep.com; GBS.Field-Manager@pttep.com"; //BONGKOT.Safety-Supt@pttep.com;
        const string CC_WeeklyEXP = CC_Team;
        const string At_WeeklyEXP = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_MatReq = "Apisada.Promkaew@halliburton.com; German.Reynosa@Halliburton.com; Jikharin.Kaew-iad@Halliburton.com; Sunisa.Prom-In@halliburton.com";
        const string CC_MatReq = CC_Team;
        const string At_MatReq = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string To_Notify = "Adisak.Ewlanta@Halliburton.com; Alan.Wiebe@Halliburton.com; Antonius.Renardi@Halliburton.com; Badung.Baroto@Halliburton.com; FSKLCPI@HALLIBURTON.COM; FSKLLABLP@Halliburton.com; German.Reynosa@Halliburton.com; jony.alamsyah@halliburton.com; Richard.Sankar@Halliburton.com; FSKLWPSMEC@halliburton.com; Grant.Devlin@halliburton.com; Chokjamnan.Tongmeekhwan@Halliburton.com; Visakha.Jiraphandh@Halliburton.com";
        const string CC_Notify = CC_Team;
        const string At_Notify = "E:\\Documents and Settings\\Ha Cac\\Desktop\\Daily_Report_ELU9924_January2012 - PTTEP.xlsx";

        const string CC_Team = "Dien.Vu@Halliburton.com; Rorsalan.Hadkhajae@Halliburton.com; Kongpop.Kumnerdpet@halliburton.com; Wikrom.Praekiat@Halliburton.com; Somsak.Jusawas@halliburton.com; Suppatee.Treechanaphan@halliburton.com";

        const string To_Test = "dien.vu@halliburton.com; hoangtucolusa@yahoo.com";
        const string CC_Test = "hoangtucolusa@gmail.com";

        const string To_Chopper = "GBS.Wellserv-supv2@pttep.com; GBS.WellService-Supv@pttep.com; KrisornB@pttep.com; Richard.Sankar@halliburton.com; Badung.Baroto@halliburton.com; fskldisp@halliburton.com";
        const string CC_Chopper = CC_Team;

        //const string Rep_Issue = "

        const string MyComputer = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
        #endregion

        #region butDailyReport_Event
#if false
        int found = 0;
        private void butDailyReport_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(g_config[Configuration.Paths.FILE_DailyReport]))
                if (System.IO.File.Exists(g_config[Configuration.Paths.FILE_DailyReport]))
                {   // Khong trong
                    System.Diagnostics.Process.Start(g_config[Configuration.Paths.FILE_DailyReport]); return;
                }

            // NULL OR EMPTY OR NOT EXIST
            DienLib.PopUp.PopUpOK.ShowDialog("No Daily Report, Please Drag & Drop your Daily Report to this Button !");
        }

        private void butDailyReport_DragEnter(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files == null) { found = 0; return; }

            // If FOLDER or XLS FILE => ALLOW. IF FOLDER then after DROP will search for XLS FILE INSIDE
            found = 0; Regex regex = new Regex(g_config.GetPathPattern(Configuration.Paths.FILE_DailyReport)); // Use Regex Instance to increase Speed
            foreach (string file in files)
            {   // Co dinh dang giong voi Daily Report
                if (regex.IsMatch(file.ToLower())) found++;
            }
        }

        private void butDailyReport_DragOver(object sender, DragEventArgs e)
        {
            if (found > 0) e.Effects = DragDropEffects.Copy;
            else e.Effects = DragDropEffects.None;
            e.Handled = true; // Any time you modify e.Effects in a drag event handler in WPF, you need to set e.Handled = true. Otherwise the default handlers will overwrite the value you set
        }
        
        private void butDailyReport_Drop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files == null) return;

            // If FOLDER or XLS FILE => ALLOW. IF FOLDER then after DROP will search for XLS FILE INSIDE
            List<int> foundList = new List<int>();
            Regex regex = new Regex(g_config.GetPathPattern(Configuration.Paths.FILE_DailyReport)); // Use Regex Instance to increase Speed
            for (int i = 0; i < files.Length; i++)
            {
                //string ext = System.IO.Path.GetExtension(file);
                //if (string.IsNullOrEmpty(ext)) { e.Effects = DragDropEffects.None; return; } /// Truong hop FILE trang hay FOLDER khong co duoi gi thi chua SUPPORT ?

                // Co dinh dang giong voi Daily Report
                if (regex.IsMatch(files[i].ToLower())) foundList.Add(i);
            }

            if (foundList.Count > 1)
            { // Duplicate : POP UP WHICH ONE ?
                MessageBox.Show("IMPLEMENT DUPLICATE POP UP LATER");
            }
            else if (foundList.Count == 1)
            { // Only one : CODE FOR THIS FILE
                System.IO.FileInfo file = new System.IO.FileInfo(files[foundList.First()]);
                DienLib.PopUp.PopUpOK.ShowDialog(string.Format("Got this File : \"{0}\" !", file.Name), "DAILY REPORT FOUND !");
                DailyReport_ChangeNewPath(file);
            }
            else
            { // Not found
                MessageBox.Show("Not a Daily Report !");
            }
        }

        private void DailyReport_ChangeNewPath(System.IO.FileInfo file)
        {
            // Replace this file with the current file which is using in Farpac
            // Check if Current file Exist ? Yes : Delete ! No : Copy

            string dest = System.IO.Path.Combine(g_config[Configuration.Paths.FOLDER_DailyReport], file.Name);

            if (System.IO.File.Exists(g_config[Configuration.Paths.FILE_DailyReport]))
            {   // Have Current File
                DienLib.PopUp.PopUpResult res =
                    DienLib.PopUp.PopUpConfirmReplace.ShowDialog(new System.IO.FileInfo(g_config[Configuration.Paths.FILE_DailyReport]), file,
                    "Will Copy & Replace OLD Daily Report with the File you just dragged in : \r\n" +
                    string.Format("\"{0}\"", file.Name), "CHANGE NEW DAILY REPORT"); // More code show Thumbnail
                if (res == DienLib.PopUp.PopUpResult.CANCEL) return;
            }

            if (System.IO.File.Exists(dest))
            {   // Same file name
                DienLib.PopUp.PopUpResult res = DienLib.PopUp.PopUpConfirmReplace.ShowDialog(new System.IO.FileInfo(dest), file,
                    "OOOOPPPP ! Man, please check Daily Report FOLDER. The file with same name already exist : \r\n" +
                    string.Format("        \"{0}\"", file.Name), "CONFIRM REPLACE DUPLICATE FILE NAME !!!"); // More code show Thumbnail
                if (res == DienLib.PopUp.PopUpResult.CANCEL) return;
            }

            file.CopyTo(dest, true); // Copy & Overwrite

            g_config[Configuration.Paths.FILE_DailyReport] = dest;
        }
#else
        private void butDailyReport_Click(object sender, RoutedEventArgs e) { }
        private void butDailyReport_DragEnter(object sender, DragEventArgs e) { }
        private void butDailyReport_DragOver(object sender, DragEventArgs e) { }
        private void butDailyReport_Drop(object sender, DragEventArgs e) { }
#endif
        #endregion

        #region WindowDragDrop
        int foundF = 0;
        private void CustomWindow_DragEnter(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files == null) { foundF = 0; return; }

            // If FOLDER => ALLOW. IF FOLDER then after DROP will search for XLS FILE INSIDE
            foundF = 0; Regex regex = new Regex(g_config.GetPathPattern(Configuration.Paths.FOLDER_OPERATION_InUse)); // Use Regex Instance to increase Speed
            foreach (string folder in files)
            {   // Co dinh dang giong voi FOLDER_OPERATION_InUse
                if (System.IO.Directory.Exists(folder))
                    if (regex.IsMatch(System.IO.Path.GetDirectoryName(folder).ToLower())) foundF++;
            }
        }
        private void CustomWindow_DragOver(object sender, DragEventArgs e)
        {
            if (foundF > 0) e.Effects = DragDropEffects.Link;
            else e.Effects = DragDropEffects.None;
            e.Handled = true; // Any time you modify e.Effects in a drag event handler in WPF, you need to set e.Handled = true. Otherwise the default handlers will overwrite the value you set
        }
        private void CustomWindow_Drop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files == null) return;

            // If FOLDER => ALLOW. IF FOLDER then after DROP will search for XLS FILE INSIDE
            List<int> foundList = new List<int>();
            Regex regex = new Regex(g_config.GetPathPattern(Configuration.Paths.FOLDER_OPERATION_InUse)); // Use Regex Instance to increase Speed
            for (int i = 0; i < files.Length; i++)
            {
                if (System.IO.Directory.Exists(files[i]))
                    // Co dinh dang giong voi FOLDER_OPERATION_InUse
                    if (regex.IsMatch(System.IO.Path.GetDirectoryName(files[i]).ToLower())) foundList.Add(i);
            }

            if (foundList.Count > 1)
            { // Duplicate : POP UP WHICH ONE ?
                System.Windows.Forms.MessageBox.Show("IMPLEMENT DUPLICATE FOLDER_OPERATION_InUse LATER");
            }
            else if (foundList.Count == 1)
            { // Only one : CODE FOR THIS FOLDER
                System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(files[foundList.First()]);
                DienLib.PopUp.PopUpOK.ShowDialog(string.Format("Got this Folder : \"{0}\" !", folder.Name), "Folder \"OPERATION - InUse\" FOUND !");
                try { ChangeNewOperationFolderPath(folder); }
                catch (Exception ex) { DienLib.PopUp.PopUpOK.ShowDialog(ex.Message, "CHANGE NEW OPERATION - InUse MAIN FOLDER FAIL"); }
            }
            else
            { // Not found
                //System.Windows.Forms.MessageBox.Show(string.Format("Not a {0} !", "Folder Operation-InUse"));
                // Should not pop-up this otherwise when drag very very fast it will come here.
            }
        }

        private void ChangeNewOperationFolderPath(System.IO.DirectoryInfo OpFolder)
        {
            if (!OpFolder.Exists) { DienLib.PopUp.PopUpOK.ShowDialog("ChangeNewOperationFolderPath : Folder not exist \"" + OpFolder.FullName + "\"", "FOLDER NOT EXIST !!!"); return; }

            // Foreach FOLDER in OpFolder check which one match FOLDER Pattern then rewrite that FOLDER Path
            Dictionary<Configuration.Paths, string> writeDict = new Dictionary<Configuration.Paths, string>();
            writeDict.Add(Configuration.Paths.FOLDER_OPERATION_InUse, OpFolder.FullName);
            foreach (System.IO.DirectoryInfo folder in OpFolder.GetDirectories())
            {
                Configuration.Paths path = g_config.EnumFolderPaths(folder.FullName);
                if (path != Configuration.Paths.NA)
                {   // Found => Write Folder Path
                    // Check old Folder Path Exist first
                    string oldpath = g_config[path];
                    if (System.IO.Directory.Exists(oldpath))
                    {
                        DienLib.PopUp.PopUpOK.ShowDialog("You will overwrite Old Path: \"" + oldpath + "\"");
                    }
                    writeDict.Add(path, folder.FullName); // Use this to save time read write to xls file.
                    //g_config[path] = folder.FullName; // Will take much time because open & close xls file many time
                }
            }
            // IMPLEMENT CHECK WHICH BASE FOLDER MISSING THEN POP UP
            g_config.PathsUpdate(writeDict);

            // IMPLEMENT LATER
            DienLib.PopUp.PopUpOK.ShowDialog("Copy Old File Implement later !");
            return;

            // Trong tung Folder lai Kiem cac FILE nao co DayWrite muon nhat va Match thi Add vao

            // Moi loai FOLDER Match lai kiem tiep ben trong thay Match File nao thi Add vo => Implement later
        }
        #endregion

        private void butFARPAC_Click(object sender, RoutedEventArgs e)
        {
            FarpacHelper.ShowDialog();
        }

        /*
        private void sendReport(string title, string to, string cc, string attachment, string body, string signature)
        {
            Audio myAudio = new Audio();
            myAudio.Play("E:/WINDOWS/Media/ding.wav");

            #region Check Attachment Exist
            //attachment = "D:/Perf Initial.xlsx";
            if (attachment.LastIndexOf('\\') > 1 && attachment.Length > attachment.LastIndexOf('\\') + 1)
            {  // Thoa man cac yeu cau co ban cua mot duong dan file
                if (!System.IO.File.Exists(attachment))
                { // Duong dan file khong ton tai
                    string folder = attachment.Substring(0, attachment.LastIndexOf('\\'));
                    if (!System.IO.Directory.Exists(folder)) folder = "::" + MyComputer; // Khong ton tai thi Mac Dinh Computer
                    attachment = getFilePath("ATTACH FILE FOR YOUR REPORT : \"" + title + "\"",
                        attachment.Substring(attachment.LastIndexOf('\\') + 1), folder);
                }
            }
            else attachment = getFilePath("ATTACH FILE FOR YOUR REPORT : \"" + title + "\"",
                "Please attach your file", "::" + MyComputer); // Khong phai la mot duong dan file
            #endregion

            if (attachment.Length > 0)
            {
                myOutlook = new wOutlook(title, to, cc, body, signature, attachment);
                myExcel = new wExcel(attachment);
            }
            else
            {
                MessageBox.Show("You did not attached any file yet, Please ATTACH FILE YOURSELF before send !",
                "Auto Sending \"" + title + "\"", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                myOutlook = new wOutlook(title, to, cc, body, signature);
                myExcel = new wExcel();
            }

            char l = Ratio_MailExcel[0];
            byte rt_Mail = (byte)(Ratio_MailExcel[0] - '0');
            byte rt_Excel = (byte)(Ratio_MailExcel[2] - '0');

            // 2 Ways to use MoveWindow or myExcel.Top/Left & Width/Height
            myExcel.SetWorkArea(new Rectangle(SystemInformation.WorkingArea.Width * rt_Mail / (rt_Mail + rt_Excel),
                SystemInformation.WorkingArea.Y, SystemInformation.WorkingArea.Width * rt_Excel / (rt_Mail + rt_Excel),
                SystemInformation.WorkingArea.Height));

            try
            {
                myOutlook.SetWorkArea(new Rectangle(SystemInformation.WorkingArea.X, SystemInformation.WorkingArea.Y,
                SystemInformation.WorkingArea.Width * rt_Mail / (rt_Mail + rt_Excel), SystemInformation.WorkingArea.Height));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
        }

        private wExcel myExcel;
        private wOutlook myOutlook;
        const string MyComputer = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
        private string getFilePath(string title, string initFile, string initFolder)
        {
            OpenFileDialog dialog = new OpenFileDialog(); // Ton tai thi nhu ben tren da chon thu muc trich tu attachment
            dialog.InitialDirectory = initFolder;
            dialog.FileName = initFile;
            dialog.Title = title;
            dialog.ShowDialog();
            if (System.IO.File.Exists(dialog.FileName)) return dialog.FileName; else return "";
        }
        */
    }
}
